# coding=utf-8
# author=haishan09@gmail.com
import datetime
from dimension.providers.base import BaseProvider
from common.provider import provider_register


@provider_register('dimension', 'datetime')
class DatetimeProvider(BaseProvider):

    def __init__(self, conf, dim):
        super(DatetimeProvider, self).__init__(conf, dim)

    def get_choices(self, cuts={}):
        return [
            (1, '今日'),
            (2, '昨日'),
            (3, '前日'),
            (4, '前3日'),
            (5, '前7日'),
            (6, '前14日'),
            (7, '前15日'),
            (8, '前30日'),
            (9, '本周'),
            (10, '上1周'),
            (11, '本月'),
            (12, '上1月'),
        ]

    def handle_choice(self, value):
        value = int(value)
        today = datetime.date.today()
        yesterday = today - datetime.timedelta(days=1)
        if value == 1:
            return today
        elif value == 2:
            return yesterday
        elif value == 3:
            d2_before = today - datetime.timedelta(days=2)
            return d2_before
        elif value == 4:
            d3_before = today - datetime.timedelta(days=3)
            return (d3_before, yesterday)
        elif value == 5:
            d7_before = today - datetime.timedelta(days=7)
            return (d7_before, yesterday)
        elif value == 6:
            d14_before = today - datetime.timedelta(days=14)
            return (d14_before, yesterday)
        elif value == 7:
            d15_before = today - datetime.timedelta(days=15)
            return (d15_before, yesterday)
        elif value == 8:
            d30_before = today - datetime.timedelta(days=30)
            return (d30_before, yesterday)
        elif value == 9:
            pass
        elif value == 10:
            pass
        elif value == 11:
            pass
        elif value == 12:
            pass

